package com.example.tourstor.myself;

import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.tourstor.R;

public class SettingActivity extends AppCompatActivity implements MyOneLineView.OnRootClickListener, MyOneLineView.OnArrowClickListener  {

    Toolbar setting_toolbar;
    LinearLayout setting_root;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        setToolBar();
        initView();

    }


    private void setToolBar() {
        setting_toolbar = (Toolbar) findViewById(R.id.setting_toolbar);

        setting_toolbar.setTitle("设置");
        setting_toolbar.setTitleTextColor(Color.WHITE);

        this.setSupportActionBar(setting_toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//左侧添加一个默认的返回图标
        getSupportActionBar().setHomeButtonEnabled(true);//设置返回键可用
        this.getSupportActionBar().setDisplayShowTitleEnabled(true);
    }

    //Toolbar的事件---返回
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    public void initView(){

        setting_root = (LinearLayout) findViewById(R.id.setting_root);

        //使用示例，通过Java代码来创建MyOnelineView
        //icon + 文字 + 箭头
        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("安全设置", "手机号、密码", true)
                /*.setDividerTopColor(R.color.head_bottom_color)*/
                .showDivider(true,true)
                .setDividerTopHigiht(10)
                .setOnRootClickListener(this, 1));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("生物识别", "人脸、指纹、声纹", true)
                .setOnRootClickListener(this, 2));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("支付设置", "", true)
                .showDivider(true,true)
                .setDividerTopHigiht(10)
                .setOnRootClickListener(this, 3));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("通用", "", true)
                .setOnRootClickListener(this, 4));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("快捷方式设置", "", true)
                .setOnRootClickListener(this, 5));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("隐私", "", true)
                .showDivider(true,true)
                .setDividerTopHigiht(10)
                .setOnRootClickListener(this, 6));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("求助反馈", "", true)
                .setOnRootClickListener(this, 7));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("关于", "版本号 1.0", true)
                .setOnRootClickListener(this, 8));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("换帐号登录", "", true)
                .showDivider(true,true)
                .setDividerTopHigiht(10)
                .setOnRootClickListener(this, 9));

        setting_root.addView(new MyOneLineView(this)
                .initNoIcon("退出登录", "", true)
                .setOnRootClickListener(this, 10));


    }

    @Override
    public void onRootClick(View view) {

        switch ((int) view.getTag()) {
            case 1:
                Toast.makeText(this, "111", Toast.LENGTH_SHORT).show();
                break;
            case 2:
                Toast.makeText(this, "222", Toast.LENGTH_SHORT).show();
                break;
            case 3:
                Toast.makeText(this, "333", Toast.LENGTH_SHORT).show();
                break;
            case 4:
                Toast.makeText(this, "333", Toast.LENGTH_SHORT).show();
                break;
            case 5:
                Toast.makeText(this, "555", Toast.LENGTH_SHORT).show();
                break;
            case 6:
                Toast.makeText(this, "666", Toast.LENGTH_SHORT).show();
                break;
            case 7:
                Toast.makeText(this, "777", Toast.LENGTH_SHORT).show();
                break;
            case 8:
                //Toast.makeText(this, "888", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(SettingActivity.this, AboutActivity.class));
                break;
            case 9:
                Toast.makeText(this, "999", Toast.LENGTH_SHORT).show();
                break;
            case 10:
                Toast.makeText(this, "10", Toast.LENGTH_SHORT).show();
                break;
        }

    }

    @Override
    public void onArrowClick(View view) {

    }
}
